package com.pzcnet.model;

import com.pzcnet.util.JSONUtil;
import lombok.Data;

/**
 * Created by xdkxlk on 2017/9/10.
 */
@Data
public class EventPublish extends Event {

    public enum EventPublishStatus {
        NEW,
        PUBLISHING,
        PUBLISHED,
        REPEAT,
        ERROR;
    }

    public EventPublish() {

    }

    public EventPublish(int id, String eventType, String payload, String eventStatus) {
        super(id, eventType, payload);
        this.eventStatus = eventStatus;
    }

    private String eventStatus;

    private Integer repeat;

    public static EventPublishBuilder builder() {
        return new EventPublishBuilder();
    }

    public static class EventPublishBuilder {

        private int id;

        private String eventType;

        private String payload;

        private String eventStatus;

        public EventPublish build() {
            return new EventPublish(id, eventType, payload, eventStatus);
        }

        public EventPublishBuilder id(int id) {
            this.id = id;
            return this;
        }

        public EventPublishBuilder eventType(EventType eventType) {
            this.eventType = eventType.toString();
            return this;
        }

        public EventPublishBuilder payload(Payload payload) {
            this.payload = JSONUtil.getJSON(payload);
            return this;
        }

        public EventPublishBuilder eventStatus(EventPublishStatus eventPublishStatus) {
            this.eventStatus = eventPublishStatus.toString();
            return this;
        }
    }
}
